package com.reading.controller;

import com.github.pagehelper.PageInfo;
import com.reading.pojo.web.Classification;
import com.reading.pojo.web.Tagclass;
import com.reading.service.ClassificationService;
import com.reading.service.TagclassService;
import com.reading.vo.Rmed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/classification")
public class ClassificationController {
    @Autowired
    private ClassificationService classificationService;
    //查询分类
    @RequestMapping("/findclassification")
    public Rmed findclassification(@RequestBody Classification classification,Integer pageNo,Integer pageSize){
        PageInfo pageInfo = classificationService.findclassification(classification,pageNo,pageSize);
        return Rmed.suceessData(pageInfo);
    }
    //添加
    @RequestMapping("/add")
    public Rmed add(@RequestBody Classification classification){
        try {
            if (classification.getId()==null){
                classificationService.add(classification);
            }else{
                classificationService.update(classification);
            }
            return Rmed.suceessData("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rmed.error("添加失败");
    }
    //删除
    @RequestMapping("/delete")
    public Rmed delete(Integer id){
        try {
            classificationService.delete(id);
            return Rmed.suceessData("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rmed.error("删除失败");
    }
}
